package com.seata.demo.seatauser.controller;

import com.seata.demo.seatauser.entity.User;
import com.seata.demo.seatauser.feign.RoleFeign;
import com.seata.demo.seatauser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {
    @Autowired
    UserService userService;

    @Autowired
    RoleFeign roleFeign;

    @PostMapping("/user/add")
    public void add(@RequestBody User user){
        userService.insert(user);
    }

    @PostMapping("/user/addUserRole")
    public void addUserRole(@RequestBody User user){
        userService.addUserRole(user);
    }

    @GetMapping("/user/test")
    public void test(){
        userService.test();
    }

    @GetMapping("/testFeign")
    public String testFeign(@RequestParam("id") String id){
        switch (id){
            case "1":{
                return "成功";
            }
            case "2": {
                return "no yes";
            }
            case "3":{
                int a=1/0;
            }
            case "4":{
                throw new RuntimeException("非法参数异常");
            }
        }
        return "";
    }
}
